/**
 * @version Create on 2012-11-2
 * @author Yinzi Chen
 */

public class LongestCommonPrefix {

	public String longestCommonPrefix(String[] strs) {
		if (strs.length == 0)
			return "";
		int i = 0;
		while (true) {
			if (strs[0].length() <= i)
				break;
			for (int j = 1; j < strs.length; ++j) {
				if (strs[j].length() <= i
						|| strs[j].charAt(i) != strs[j - 1].charAt(i))
					return strs[0].substring(0, i);
			}
			i++;
		}
		return strs[0].substring(0, i);
	}

	public static void main(String[] args) {

	}

}
